<html>
<head><meta charset="utf-8"><title>Design meeting 2021-01-20 · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Design.20meeting.202021-01-20.html">Design meeting 2021-01-20</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="223265796"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Design%20meeting%202021-01-20/near/223265796" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Design.20meeting.202021-01-20.html#223265796">(Jan 19 2021 at 17:58)</a>:</h4>
<p>Dear <span class="user-group-mention" data-user-group-id="1977">@T-lang</span>,</p>
<p>The <span class="user-group-mention" data-user-group-id="1175">@WG-rfc-2229</span> folks and I prepared a document for use in the design meeting tomorrow:</p>
<p><a href="https://hackmd.io/wPs-tHJZR1Cj9j_vwsxwbw?view">https://hackmd.io/wPs-tHJZR1Cj9j_vwsxwbw?view</a></p>
<p>Feel free to take a look, but I think we intend to start the meeting by reviewing its contents, so to some extent it's an "outline" for the kinds of things we want to cover.</p>



<a name="223265893"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Design%20meeting%202021-01-20/near/223265893" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Design.20meeting.202021-01-20.html#223265893">(Jan 19 2021 at 17:58)</a>:</h4>
<p>I just realized that the doc does not include a concrete list of questions we hope to answer or a least get people thinking about</p>



<a name="223265897"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Design%20meeting%202021-01-20/near/223265897" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Design.20meeting.202021-01-20.html#223265897">(Jan 19 2021 at 17:58)</a>:</h4>
<p>I will try to add that</p>



<a name="223265917"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Design%20meeting%202021-01-20/near/223265917" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Design.20meeting.202021-01-20.html#223265917">(Jan 19 2021 at 17:58)</a>:</h4>
<p>Or maybe <span class="user-mention" data-user-id="281950">@Aman Arora</span> you could take a stab if you have a sense of them :)</p>



<a name="223275039"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Design%20meeting%202021-01-20/near/223275039" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Design.20meeting.202021-01-20.html#223275039">(Jan 19 2021 at 18:57)</a>:</h4>
<p>Updated the doc</p>



<a name="223410870"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Design%20meeting%202021-01-20/near/223410870" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Design.20meeting.202021-01-20.html#223410870">(Jan 20 2021 at 18:02)</a>:</h4>
<p>Am I in the wrong zoom room?</p>



<a name="223411039"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Design%20meeting%202021-01-20/near/223411039" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Design.20meeting.202021-01-20.html#223411039">(Jan 20 2021 at 18:03)</a>:</h4>
<p><span class="user-mention" data-user-id="125270">@scottmcm</span> maybe?</p>



<a name="223411105"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Design%20meeting%202021-01-20/near/223411105" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Design.20meeting.202021-01-20.html#223411105">(Jan 20 2021 at 18:04)</a>:</h4>
<p>Hello <span class="user-group-mention" data-user-group-id="1977">@T-lang</span> -- design meeting now</p>



<a name="223418915"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Design%20meeting%202021-01-20/near/223418915" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Design.20meeting.202021-01-20.html#223418915">(Jan 20 2021 at 19:02)</a>:</h4>
<p>I think I'm less concerned about a specific percentage of <code>let x = x;</code> and more about an admittedly-fuzzy "do the ones that show up seem reasonable".</p>



<a name="223423861"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Design%20meeting%202021-01-20/near/223423861" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Design.20meeting.202021-01-20.html#223423861">(Jan 20 2021 at 19:37)</a>:</h4>
<p><span class="user-mention" data-user-id="125270">@scottmcm</span> Agreed. If all of those we end up with are necessary for correctness, that's fine.</p>



<a name="223432111"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Design%20meeting%202021-01-20/near/223432111" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Design.20meeting.202021-01-20.html#223432111">(Jan 20 2021 at 20:40)</a>:</h4>
<p>Hmm, I think it's more than "necessary for correctness" -- if they become necessary in situations that don't feel in some way "yeah, that code's doing something tricky" then I'd have concerns that the rules might not be the right ones, even if the migration fixes were perfect.</p>



<a name="223505615"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Design%20meeting%202021-01-20/near/223505615" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Design.20meeting.202021-01-20.html#223505615">(Jan 21 2021 at 13:15)</a>:</h4>
<p>One question that remains a bit unclear from the hackmds alone (don't have time to see the recording), is the difference between the suggested <code>let x = x;</code>, which makes the closure not be more than <code>FnOnce</code> if <code>x</code> is not <code>Copy</code>, _vs._ <code>if false { let _x = x; loop {} }</code>, which just makes the closure <em>capture <code>x</code></em> without necessarily <em>consuming</em> it when called (same as currently doing <code>let _ = x;</code> in a <code>move</code> closure).<br>
<a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=90049afee37fc9377ca13c89523d8d4b">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=90049afee37fc9377ca13c89523d8d4b</a></p>



<a name="223560431"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Design%20meeting%202021-01-20/near/223560431" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Design.20meeting.202021-01-20.html#223560431">(Jan 21 2021 at 19:41)</a>:</h4>
<p>Hmm</p>



<a name="223560559"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Design%20meeting%202021-01-20/near/223560559" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Design.20meeting.202021-01-20.html#223560559">(Jan 21 2021 at 19:42)</a>:</h4>
<p>Huh</p>



<a name="223560575"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Design%20meeting%202021-01-20/near/223560575" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Design.20meeting.202021-01-20.html#223560575">(Jan 21 2021 at 19:42)</a>:</h4>
<p>I had kind of overlooked the <code>FnOnce</code> interaction</p>



<a name="223560591"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Design%20meeting%202021-01-20/near/223560591" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Design.20meeting.202021-01-20.html#223560591">(Jan 21 2021 at 19:42)</a>:</h4>
<p>I was thinking "oh, it moves anyway, so it must be <code>FnOnce</code>", but of course that's not true for a move closure</p>



<a name="223560616"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Design%20meeting%202021-01-20/near/223560616" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Design.20meeting.202021-01-20.html#223560616">(Jan 21 2021 at 19:42)</a>:</h4>
<p>(I do regret that name)</p>



<a name="223560640"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Design%20meeting%202021-01-20/near/223560640" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Design.20meeting.202021-01-20.html#223560640">(Jan 21 2021 at 19:43)</a>:</h4>
<p>Good catch <span class="user-mention" data-user-id="232018">@Daniel Henry-Mantilla</span></p>



<a name="223560649"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Design%20meeting%202021-01-20/near/223560649" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Design.20meeting.202021-01-20.html#223560649">(Jan 21 2021 at 19:43)</a>:</h4>
<p>cc <span class="user-mention" data-user-id="281950">@Aman Arora</span> <span aria-label="point up" class="emoji emoji-1f446" role="img" title="point up">:point_up:</span></p>



<a name="223560656"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Design%20meeting%202021-01-20/near/223560656" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Design.20meeting.202021-01-20.html#223560656">(Jan 21 2021 at 19:43)</a>:</h4>
<p>we should file a bug on this</p>



<a name="223561932"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Design%20meeting%202021-01-20/near/223561932" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Design.20meeting.202021-01-20.html#223561932">(Jan 21 2021 at 19:53)</a>:</h4>
<p>I think I understand the problem, but not the example. <code>if false { let _x = x; loop {} }</code> will consume x today and therefore make the closure at best FnOnce</p>



<a name="223563754"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Design%20meeting%202021-01-20/near/223563754" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Design.20meeting.202021-01-20.html#223563754">(Jan 21 2021 at 20:08)</a>:</h4>
<p>how would the migration work if <code>x</code> is actually <code>self</code>? you can't rebind that, so would you rename it throughout the closure?</p>



<a name="223586736"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Design%20meeting%202021-01-20/near/223586736" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Design.20meeting.202021-01-20.html#223586736">(Jan 21 2021 at 23:40)</a>:</h4>
<p><span class="user-mention silent" data-user-id="138448">cuviper</span> <a href="#narrow/stream/213817-t-lang/topic/Design.20meeting.202021-01-20/near/223563754">said</a>:</p>
<blockquote>
<p>how would the migration work if <code>x</code> is actually <code>self</code>? you can't rebind that, so would you rename it throughout the closure?</p>
</blockquote>
<p>I hadn't thought of that. Hmm I think I have seen <code>this: Self</code> as a closure parameter, so maybe that. But that also means that all the rest of the code would have to use <code>this</code> instead of self</p>



<a name="223591409"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Design%20meeting%202021-01-20/near/223591409" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Design.20meeting.202021-01-20.html#223591409">(Jan 22 2021 at 00:51)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232018">Daniel Henry-Mantilla</span> <a href="#narrow/stream/213817-t-lang/topic/Design.20meeting.202021-01-20/near/223505615">said</a>:</p>
<blockquote>
<p>One question that remains a bit unclear from the hackmds alone (don't have time to see the recording), is the difference between the suggested <code>let x = x;</code>, which makes the closure not be more than <code>FnOnce</code> if <code>x</code> is not <code>Copy</code>, _vs._ <code>if false { let _x = x; loop {} }</code>, which just makes the closure <em>capture <code>x</code></em> without necessarily <em>consuming</em> it when called (same as currently doing <code>let _ = x;</code> in a <code>move</code> closure).<br>
<a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=90049afee37fc9377ca13c89523d8d4b">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=90049afee37fc9377ca13c89523d8d4b</a></p>
</blockquote>
<p>If we have </p>
<div class="codehilite"><pre><span></span><code>let x: String;

let c = || {
    let _ = x;
};
</code></pre></div>
<p>And your concern is that if we did migration using <code>let x = x</code>, the closure would be <code>FnOnce</code> instead of <code>Fn</code>. </p>
<div class="codehilite"><pre><span></span><code>let c = || {
    let x = x;
    let _ = x;
};
</code></pre></div>
<p>If I understand this correctly, we can detect places that aren't used within the closure (x is mentioned but not used) and not migrate for them. We would've to be careful when we <a href="https://github.com/rust-lang/project-rfc-2229/issues/27">fix match</a> to not always capture the place being matched on.</p>



<a name="223591926"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Design%20meeting%202021-01-20/near/223591926" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Design.20meeting.202021-01-20.html#223591926">(Jan 22 2021 at 00:59)</a>:</h4>
<p><span class="user-mention silent" data-user-id="281950">Aman Arora</span> <a href="#narrow/stream/213817-t-lang/topic/Design.20meeting.202021-01-20/near/223586736">said</a>:</p>
<blockquote>
<p>Hmm I think I have seen <code>this: Self</code> as a closure parameter, so maybe that.</p>
</blockquote>
<p>Sure, you can also see <code>this</code> used in wrapper types like <code>Rc</code> that don't want to impede auto-deref method resolution to the inner type. So that's a reasonable candidate, assuming <code>this</code> is not already present, but it's a much more invasive change to rename it throughout the closure.</p>



<a name="223626167"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Design%20meeting%202021-01-20/near/223626167" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Design.20meeting.202021-01-20.html#223626167">(Jan 22 2021 at 10:49)</a>:</h4>
<p><span class="user-mention" data-user-id="281950">@Aman Arora</span> note that I don't know how the MIR lowering and "detecting" captures works exactly, or rather, how it is being implemented in that RFC. <strong>Currently</strong>, since the detection is done "syntactically" rather than "semantically" (sorry for the loose terminology, but, again, I don't know the implementation details, just empirical results), then unreachable code that requires owned access to the capture will:</p>
<ul>
<li>trigger a capture-by-move due to the "syntactical rules";</li>
<li>still not restrict the closure to be <code>FnOnce()</code>, since <em>the code that consumes the capture is "semantically" understood as unreachable (and diverging) and thus can be "disregarded move/borrow-wise"</em>.</li>
</ul>
<p>(This current <em>status quo</em> can be seen in the Playground I linked). Since the RFC seems to be changing the way the captures work so that it becomes smarter, I imagine the RFC implementation will (if it doesn't do it already), not trigger a capture-by-move thanks to a "semantic" interpretation of the closure: "captures in trivially unreachable-and-diverging code can be disregarded" we could say (in that regard your "we can detect places that aren't used within the closure" seems very relevant).</p>
<p>I am not saying that there is actually an issue (I don't know exactly what the RFC is doing, so I can't judge that) I just wanted to raise awareness about this "move something but in trivially unreachable code" situation <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span> (especially with the added challenge of trying to feature "migration fixes").</p>



<a name="223717186"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Design%20meeting%202021-01-20/near/223717186" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Design.20meeting.202021-01-20.html#223717186">(Jan 22 2021 at 23:49)</a>:</h4>
<p>An update from today's 2229 sync:</p>
<ul>
<li>
<p>For code that may be unreacheable but use a variable, the feature will consider it a capture. One of the motivations for this is to prevent subtle changes to drop order and closure trait,  eg in cases where the user just used an <code>if false { }</code> as an alternative to commenting out some code.</p>
</li>
<li>
<p>We decided on a new migration, possibly via some macro(TBD) like <code>capture!(x)</code>, which would desugar to <code>drop(&amp;x)</code>. This will force a move without actually taking ownership. This would also solve the problem of having to deal with <code>self</code>.</p>
</li>
</ul>



<a name="223733243"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Design%20meeting%202021-01-20/near/223733243" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Design.20meeting.202021-01-20.html#223733243">(Jan 23 2021 at 05:37)</a>:</h4>
<p>One thing I realized we missed in the meeting (or I don't remember going over in too many details) is Box performance<br>
eg: </p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">f</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">tuple</span>: <span class="nb">Box</span><span class="o">&lt;</span><span class="p">([</span><span class="nb">String</span><span class="p">;</span><span class="w"> </span><span class="mi">4096</span><span class="p">],</span><span class="w"> </span><span class="nb">String</span><span class="p">);</span><span class="w"></span>

<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">c</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">move</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">move_value</span><span class="p">(</span><span class="n">tuple</span><span class="p">.</span><span class="mi">0</span><span class="p">);</span><span class="w"> </span><span class="c1">// This is really (*tuple).0</span>
<span class="w">    </span><span class="p">};</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>Since the stack contains <code>tuple</code>, we will move *tuple.0 into the closure which is this really large value <code>[String; 4096]</code>.</p>



<a name="223733263"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Design%20meeting%202021-01-20/near/223733263" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Design.20meeting.202021-01-20.html#223733263">(Jan 23 2021 at 05:37)</a>:</h4>
<p>Do we want to special case box or let the user know that this results in a fairly large move operation?</p>



<a name="224072894"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Design%20meeting%202021-01-20/near/224072894" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Design.20meeting.202021-01-20.html#224072894">(Jan 26 2021 at 17:25)</a>:</h4>
<p><span class="user-mention" data-user-id="281950">@Aman Arora</span> i thought that this would move <code>tuple</code> and not <code>tuple.0</code></p>



<a name="224072989"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Design%20meeting%202021-01-20/near/224072989" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Design.20meeting.202021-01-20.html#224072989">(Jan 26 2021 at 17:26)</a>:</h4>
<p><code>tuple.0</code> is actually <code>(*tuple).0</code>, and hence the big array is not actually stored on the stack</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>